"""
########################################
文件描述：获取项目根目录的方法
########################################
"""
import os
from pathlib import Path
import re
import sys
import logging

def base_path():
    cur_path = os.path.dirname(__file__)
    b_path = Path(cur_path)
    project_name = "HXF_APITest" # 当前代码工程项目名称
    a = re.match(r'[^@]*\\' + project_name +'$', str(b_path))
    i = 0
    while a is None:
        b_path = b_path.parent
        i += 1
        a = re.match(r'[^@]*\\' + project_name + '$', str(b_path))
        if i > 20:
            logging.error('base_path.py：路径错误，请确认项目名称是否填写正确（%s）',i)
            sys.exit(-1)
    return str(b_path)
# print(base_path())